home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / linedrw.exe / BOXES.C < prev    next >
Text File  |  1991-11-22  |  4KB  |  164 lines

  1. //─────────────────────────────────────────────────────────────────────────────
  2. // BOXES.C
  3. //
  4. // A short & simple demonstation of how to include BOX.H in your programs to
  5. // easily access the line drawing characters.
  6. //
  7. // Written in Turbo C++ by Steve Raeburn
  8. // Contact me on CIX as sraeburn or Compuserve as 100015,3620
  9. // 
  10. //─────────────────────────────────────────────────────────────────────────────
  11.  
  12. #include <stdio.h>
  13. #include <conio.h>
  14. #include <dos.h>
  15. #include "box.h"
  16.  
  17. char far *vid_mem;
  18.  
  19. void init_video();
  20. void shade(int, int, int, int, char);
  21. void rectangle(int, int, int, int, char, char);
  22. void border(int, int, int, int, int, char);
  23. void write_char(int, int, char);
  24. void write_attrib(int, int, char);
  25. void fill_screen();
  26.  
  27.  
  28. void init_video()
  29. {
  30.     union REGS r;
  31.  
  32.  
  33.     r.h.ah = 0x00;          // Set Video Mode
  34.     r.h.al = 0x03;          // 80 x 25 16 colour text mode;
  35.     int86(0x10, &r, &r);
  36.  
  37.     vid_mem = (char far *) 0xb8000000;
  38. }
  39.  
  40. void shade(int startx, int starty, int endx, int endy, char attrib)
  41. {
  42.     register int x, y;
  43.  
  44.     for(y=starty; y<endy+1; y++)
  45.         for(x=startx; x<endx+1; x++)
  46.             write_attrib(x, y, attrib);
  47. }
  48.  
  49. void rectangle(int startx, int starty, int endx, int endy,
  50.         char attrib, char ch)
  51. {
  52.     register int x, y;
  53.  
  54.     for(y=starty; y<endy+1; y++)
  55.         for(x=startx; x<endx+1; x++)
  56.             {
  57.             write_char(x, y, ch);
  58.             write_attrib(x, y, attrib);
  59.             }
  60. }
  61.  
  62. void border(int startx, int starty, int endx, int endy, int type, char color)
  63. {
  64.     register int i;
  65.  
  66.     for(i=startx+1; i<endx; i++)
  67.         {
  68.         write_char(i, starty, box[type][1]);
  69.         write_attrib(i, starty, color);
  70.         write_char(i, endy, box[type][1]);
  71.         write_attrib(i, endy, color);
  72.         }
  73.     for(i=starty+1; i<endy; i++)
  74.         {
  75.         write_char(startx, i, box[type][4]);
  76.         write_attrib(startx, i, color);
  77.         write_char(endx, i, box[type][4]);
  78.         write_attrib(endx, i, color);
  79.         }
  80.     write_char(startx, starty, box[type][0]);
  81.     write_attrib(startx, starty, color);
  82.     write_char(startx, endy  , box[type][8]);
  83.     write_attrib(startx, endy, color);
  84.     write_char(endx, starty, box[type][3]);
  85.     write_attrib(endx, starty, color);
  86.     write_char(endx  , endy  , box[type][10]);
  87.     write_attrib(endx, endy, color);
  88. }
  89.  
  90. void write_char(int x, int y, char ch)
  91. {
  92.     register int i;
  93.     char far *v;
  94.  
  95.     v = vid_mem;
  96.     v += (x-1)*2 + ((y-1)*160);
  97.     *v = ch;
  98. }
  99.  
  100. void write_attrib(int x, int y, char attrib)
  101. {
  102.     register int i;
  103.     char far *v;
  104.  
  105.     v = vid_mem;
  106.     v += (x-1)*2 + ((y-1)*160) + 1;
  107.     *v = attrib;
  108. }
  109.  
  110. void fill_screen()
  111. {
  112.     register int x, y;
  113.  
  114.     y=0;
  115.     for(x=0; x<41; x++)
  116.         {
  117.         if(x%3==0) y++;
  118.         rectangle(40-x, 12-y, 40+x, 12+y, BLACK, 219);
  119.         }
  120. }
  121.  
  122. void main()
  123. {
  124.     int n;
  125.  
  126.     init_video();
  127.     clrscr();
  128.     rectangle(1, 1, 80, 25, 0x71, 176);
  129.     rectangle(2, 2, 79, 6, 0x1f, 32);
  130.     border(2, 2, 79, 6, 2, 0x17);
  131.     rectangle(1, 25, 80, 25, 0x0f, 32);
  132.     gotoxy(37, 2);
  133.     textcolor(WHITE);
  134.     textbackground(BLUE);
  135.     cprintf("BOXES");
  136.     gotoxy(5, 4);
  137.     cprintf("A demonstration of BOX.H - Used to create boxes & line draw characters");
  138.     gotoxy(1, 25);
  139.     textcolor(WHITE);
  140.     textbackground(BLACK);
  141.     for(n=0; n<5; n++)
  142.         {
  143.         shade((n*16)+3, 11, (n*16)+14, 16, DARKGRAY);
  144.         rectangle((n*16)+2, 10, (n*16)+13, 15, (n+1)*16+7, 32);
  145.         border((n*16)+2, 10, (n*16)+13, 15, n, (n+1)*16+15);
  146.         cprintf("Box type %d%c", n, 0x07);
  147.         gotoxy(1,25);
  148.         sleep(2);
  149.         }
  150.     cprintf("This program written by Steve Raeburn :CIX sraeburn COMPUSERVE 100015,3620");
  151.     gotoxy(1,25);
  152.     shade(3, 19, 79, 23, DARKGRAY);
  153.     rectangle(2, 18, 78, 22, 0x7f, 32);
  154.     border(2, 18, 78, 22, 4, 0x71);
  155.     textcolor(LIGHTBLUE);
  156.     textbackground(LIGHTGRAY);
  157.     gotoxy(8, 20);
  158.     cprintf("All borders shown were created with the same routine using BOX.H");
  159.     gotoxy(80,25);
  160.     sleep(5);
  161.     fill_screen();
  162.     clrscr();
  163. }
  164.